import csv
import json

lng_prefixes = ['zh','en']

for idx in range(len(lng_prefixes)):
	lng = lng_prefixes[idx]
	if lng == None:
		continue
	data = {}
	with open('translations.csv', encoding="utf-8") as csv_file:
		csv_reader = csv.reader(csv_file, delimiter=';')
		for row in csv_reader:
			print(row)
			if len(row) >= len(lng_prefixes) + 2:
				if (row[0] not in data):
					data[row[0]] = {}
				data[row[0]][row[1]] = row[idx + 2]
			elif len(row) == 0:
				continue
			else:
				print(row)
				print(row[0] + "," + row[1] + "," + str(len(row)))
				print("Not enough Items: " + row[0] + "." + row[1])
				raise

	with open('../src/plugins/i18n/translations/' + lng + '.ts', 'w', encoding="utf-8") as outfile:
		outfile.write('export default ')
		json.dump(data, outfile, ensure_ascii=False, indent=4)
